package org.enhance.idempotent.mysql.config;

import org.enhance.common.annotation.ConditionalOnProperties;
import org.enhance.idempotent.core.config.IdempotentCoreAutoConfiguration;
import org.enhance.idempotent.core.config.properties.IdempotentCoreProperties;
import org.enhance.idempotent.mysql.MySqlIdempotentRepositoryImpl;
import org.enhance.idempotent.mysql.mapper.BusinessIdempotentMapper;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.autoconfigure.AutoConfigureAfter;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.lang.NonNull;

/**
 * 自动配置
 *
 * @author wenpanfeng 2023/01/04 18:05
 */
@Configuration
@MapperScan(value = {"org.enhance.idempotent.mysql.mapper"})
@AutoConfigureAfter({IdempotentCoreAutoConfiguration.class})
@ConditionalOnProperties(prefix = IdempotentCoreProperties.PREFIX,
        properties = {"enable", "adapter.mysql.enable"}, values = {"true", "true"})
public class IdempotentAdapterDbAutoConfiguration {

    @Bean(name = "mySqlIdempotentRepository")
    @ConditionalOnMissingBean(name = "mySqlIdempotentRepository")
    public MySqlIdempotentRepositoryImpl mySqlIdempotentRepository(@NonNull BusinessIdempotentMapper businessIdempotentMapper) {
        return new MySqlIdempotentRepositoryImpl(businessIdempotentMapper);
    }

}
